const allnav = document.querySelector('.all-nav')//总导航栏
const nav = document.querySelector('.nav')//上部导航栏
const navb = document.querySelector('.navb')//下拉菜单
nav.addEventListener('mouseenter', () => {
  navb.style.opacity = 1
})
allnav.addEventListener('mouseleave', () => {
  navb.style.opacity = 0
})        //实现下拉菜单
const li1 = document.querySelectorAll('.nav li:not(:first-child):not(:last-child)')//导航栏的tab切换
for (let i = 0; i < li1.length; i++) {
  li1[i].addEventListener('mouseenter', function () {
    this.classList.add('active')
  })
}
for (let i = 0; i < li1.length; i++) {
  li1[i].addEventListener('mouseleave', function () {
    this.classList.remove('active')
  })
}
const p = document.querySelector('header .ajax p')
p.innerHTML = new Date().toLocaleString()
setInterval(function ajax() {
  const xhr = new XMLHttpRequest()
  xhr.open('GET', 'http://quan.suning.com/getSysTime.do')
  xhr.send()
  xhr.onreadystatechange = function () {
    if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
      const Time = JSON.parse(xhr.responseText).sysTime2
      p.innerHTML = Time
    }
  }
}, 1000)
const YHname = document.querySelector('header span')
if (localStorage.getItem('uname') !== null) {
  YHname.innerText = `用户${localStorage.getItem('uname')}`
}